#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2019/2/25 13:41
# @Author  : yangdy
# @Email   : yangdy@egu360.com
# @File    : 合并两个有序数组.py
# @Software: PyCharm


class Solution:
    def merge(self, nums1: 'List[int]', m: 'int', nums2: 'List[int]', n: 'int') -> 'None':
        """
        Do not return anything, modify nums1 in-place instead.
        """
        l1 = len(nums1)
        i1, i2, j = m - 1, n - 1, l1 - 1
        while n and (i1 >= 0 or i2 >= 0):
            if (i1 >= 0)and(i2 < 0 or nums1[i1] >= nums2[i2]):
                nums1[j] = nums1[i1]
                i1 -= 1
                j -= 1
            elif (i2 >= 0)and(i1 < 0 or nums1[i1] < nums2[i2]):
                nums1[j] = nums2[i2]
                i2 -= 1
                j -= 1
            else:
                break


solve = Solution()

nums1, m = [0], 0
nums2, n = [1], 1
print('problem:', nums1, m, nums2, n)
solve.merge(nums1=nums1, m=m, nums2=nums2, n=n)
print('ans:', nums1)

nums1, m = [1, 0], 1
nums2, n = [2], 1
print('problem:', nums1, m, nums2, n)
solve.merge(nums1=nums1, m=m, nums2=nums2, n=n)
print('ans:', nums1)
